//
//  RMMMySkillTableViewCell.m
//  Romomo
//
//  Created by puman on 16/10/9.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMMySkillTableViewCell.h"
@implementation RMMMySkillTableViewCell
{
    UIImageView *_imageV;
    UILabel *_nameLabel;
    UILabel *_yearLabel;
    UILabel *_titleLabel;
    UIImageView *_scoreImageV;
    UILabel *_scoreLabel;
    
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(15, 12.5, 65, 65)];
        _imageV.layer.cornerRadius = 65 / 2;
        _imageV.layer.masksToBounds = YES;
        [self.contentView addSubview:_imageV];
        
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_imageV.right + 15, _imageV.top, 50, 25)];
        _nameLabel.font = kBFont(16);
        [self.contentView addSubview:_nameLabel];
        
        _bookingBut = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _bookingBut.frame = CGRectMake(kScreenWideth - 75, 12, 60, 30);
        _bookingBut.layer.cornerRadius = 15;
        _bookingBut.layer.borderWidth = 1;
        _bookingBut.layer.borderColor = COLORFROMCODE(0x53C7C6 , 1).CGColor;
        [_bookingBut setTitleColor:COLORFROMCODE(0x53C7C6 , 1) forState:(UIControlStateNormal)];
        _bookingBut.titleLabel.font = kBFont(13);
        [_bookingBut setTitle:@"预约" forState:(UIControlStateNormal)];
        [self.contentView addSubview:_bookingBut];
        
        _yearLabel = [[UILabel alloc] initWithFrame:CGRectMake(_nameLabel.right + 8, _nameLabel.top + 3.5, 30, 18)];
        _yearLabel.textColor = kWhiteColor;
        _yearLabel.backgroundColor = RGBA(236, 194, 66, 1);
        _yearLabel.textAlignment = NSTextAlignmentCenter;
        _yearLabel.font = kBFont(12);
        _yearLabel.layer.masksToBounds = YES;
        _yearLabel.layer.cornerRadius = 3;
        [self.contentView addSubview:_yearLabel];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_nameLabel.left, _nameLabel.bottom + 6, kScreenWideth - _nameLabel.left, 14)];
        _titleLabel.font = kFont(12);
        [self.contentView addSubview:_titleLabel];
     
        [self.contentView addSubview:_scoreImageV];
        for (int i = 0; i < 5; i++) {
            UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(_nameLabel.left + 16 * i, _titleLabel.bottom + 8, 12, 12)];
            imageV.tag = 10000 + i;
            imageV.image = [UIImage imageNamed:@"星1-2@3x"];
            [self.contentView addSubview:imageV];
        }

        _scoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(_nameLabel.left + 80, _titleLabel.bottom + 8, 40, 12)];
        _scoreLabel.textColor = COLORFROMCODE(0x9B9B9B , 1);
        _scoreLabel.font = kFont(10);
        [self.contentView addSubview:_scoreLabel];
        
        UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(_nameLabel.left, 89.5, kScreenWideth - _nameLabel.left - 15, 0.5)];
        lineLabel.backgroundColor = COLORFROMCODE(0xEEEEEE, 1);
        [self.contentView addSubview:lineLabel];
    }
    return self;
}
- (void)setDic:(NSDictionary *)dic{
    _scoreLabel.text = [NSString stringWithFormat:@"%@分",[RMMFileManager retrunObjWith:dic[@"EVALUATE_DETAILS"][@"AVERAGE_SCORE"]]];
    _titleLabel.text = [RMMFileManager retrunObjWith:dic[@"EMP_DESCRIBE"]];
    _nameLabel.text = [RMMFileManager retrunObjWith:dic[@"EMPLOYEE_NAME"]];
    _yearLabel.text =  [NSString stringWithFormat:@"%@年",[RMMFileManager retrunObjWith:dic[@"ANNUAL_LEAVE"]]];
    [_imageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kBaseImageUrl,[RMMFileManager retrunObjWith:dic[@"EMP_IMG"]]]] placeholderImage:[UIImage imageNamed:@"加载中@3x"]];
    CGFloat width = [UILabel backHeightWithString:_nameLabel.text CGFloatCount:25 metho:WIDTH font:16];
    _nameLabel.frame = CGRectMake(_imageV.right + 15, _imageV.top, width + 10, 25);
    CGFloat widthY = [UILabel backHeightWithString:_yearLabel.text CGFloatCount:18 metho:WIDTH font:12];
    _yearLabel.frame =  CGRectMake(_nameLabel.right, _nameLabel.top + 3.5, widthY + 10, 18);
    [self setStarWith:[RMMFileManager retrunObjWith:dic[@"EVALUATE_DETAILS"][@"AVERAGE_SCORE"]]];
}
- (void)setStarWith:(NSString *)score{
    NSInteger s1 = [score integerValue];
    CGFloat s2 = [score floatValue];
    for (int i = 0; i < 5; i++) {
        UIImageView *imageV = [self viewWithTag:10000 + i];
        if (i < s1) {
            imageV.image = [UIImage imageNamed:@"星-1@3x"];
        } else {
            if (i >= s1 && i < s2) {
                imageV.image = [UIImage imageNamed:@"星-3@3x"];
            } else {
                imageV.image = [UIImage imageNamed:@"星1-2@3x"];
            }
        }
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
